package com.nand.module.function.ui;

import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.tabs.TabLayout;
import com.lzy.okgo.model.HttpParams;
import com.nand.library.base.base.BaseActivity;
import com.nand.library.base.base.BaseFragment;
import com.nand.module.function.R;
import com.nand.module.function.fragment.EpairAllListFragment;
import com.nand.module.function.fragment.EpairListFragment;
import com.nand.module.function.utils.LogUtils;
import com.nand.module.function.view.tablayout.XTabLayout;
import com.nand.module.function.view.tablayout.XTabLayoutAdapter;

/**
 * created by zhaowei
 * on 2019/12/24
 * 生产异常列表
 */
@Route(path = "/function/eqair/list")
public class EpairListActivity extends BaseActivity {

    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    XTabLayoutAdapter viewPagerAdapter;
    @Override
    protected int initLayout() {
        return R.layout.activity_epair_list;
    }

    @Override
    protected void initView() {
        mTabLayout = findViewById(R.id.m_epair_list_tab);
        mViewPager = findViewById(R.id.m_epair_list_vp);
    }
    @Override
    protected void initData() {
            findViewById(R.id.iv_add).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(EpairListActivity.this, EpairDetailsActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("code", 101);
                    intent.putExtras(bundle);
                    startActivityForResult(intent, 101);
                }
            });
        viewPagerAdapter = new XTabLayoutAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(viewPagerAdapter);
        //mTabLayout.setxTabDisplayNum(3);
        // mTabLayout.setTabMode(coupon_list.size() > 3 ? TabLayout.MODE_SCROLLABLE : TabLayout.MODE_FIXED);

        viewPagerAdapter = new XTabLayoutAdapter(getSupportFragmentManager());
        viewPagerAdapter.addItem(EpairListFragment.newInstance(1), "我的任务");
        viewPagerAdapter.addItem(EpairListFragment.newInstance(2), "所有单据");
        mViewPager.setAdapter(viewPagerAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.getTabAt(0).select();
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LogUtils.e("activityabc======="+requestCode +"===="+resultCode);
        if (101 == requestCode  && 0 != resultCode){
            ((EpairListFragment)viewPagerAdapter.getFragments().get(0)).setSwipeRefres();
        }
    }
}
